package com.pureland.storage.configuration;

import com.pureland.storage.MinIOStorageTemplate;
import com.pureland.storage.StorageTemplate;
import com.pureland.storage.properties.StorageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;


/**
 * @projectName: pureland_cloud
 * @className: com.pureland.storage.properties.configuration.StorageAutoConfiguration
 * @description: 对象存储自动配置类
 * @author: tong.li
 * @createTime: 2020/10/19 14:13
 * @version: v1.0
 * @copyright: 版权所有 李彤 © 2020
 */
@Configuration
@EnableConfigurationProperties(StorageProperties.class)
@ConditionalOnProperty(prefix = "pureland.storage", value = "enabled", matchIfMissing = true)
public class StorageAutoConfiguration {


    @Autowired
    private StorageProperties storageProperties;

    @Primary
    @Bean(initMethod = "init")
    public StorageTemplate storageTemplate() {
        return new MinIOStorageTemplate(storageProperties.getMinio());
    }


}
